<template>
    <div class="app-container">
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
                <el-button type="danger" plain icon="el-icon-delete" size="mini" @click="handleDelete(ids)">删除</el-button>
            </el-col>
            <right-toolbar @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="招标人代表名称" align="left" prop="name" />
            <el-table-column label="公司名称" align="left" prop="company" />
            <el-table-column label="专业类别" align="left" prop="professionType" />
            <el-table-column label="职称专业" align="left" prop="profession" />
            <el-table-column label="电话" align="center" prop="telphone" />
            <el-table-column label="身份证号" align="left" width="200" prop="idcard" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete"
                        @click="handleDelete(scope.row.agentid)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />
        <Add :modalVisible.sync="visible" :mode="mode" :current="current" :refresh="getList" />
    </div>
</template>
  
<script>
import { getAgentList, delAgent } from "@/api/unit/random";
import Add from "./components/add";

export default {
    name: "agent",
    components: {
        Add
    },
    data() {
        return {
            queryParams: {
                pageNum: 1,
                pageSize: 10
            },
            total: 0,
            showSearch: true,
            loading: false,
            list: [],
            visible: false,
            mode: 0,
            current: {},
            ids: ""
        }
    },
    created() {
        this.getList();
    },
    methods: {
        getList() {
            this.loading = true;
            getAgentList(this.queryParams).then(res => {
                this.list = res.rows;
                this.total = res.total;
            }).finally(() => this.loading = false);
        },
        handleSelectionChange(list) {
            this.ids = list.map(item => item.agentid).toString();
        },
        handleAdd() {
            this.visible = true;
            this.mode = 0;
        },
        handleUpdate(record) {
            this.mode = 1;
            this.visible = true;
            this.current = record
        },
        handleDelete(agentids) {
            if (agentids.length > 0) {
                this.$confirm("是否删除所选招标人代表", "", {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    delAgent(agentids).then(res => {
                        if (res.code == 200) {
                            this.getList();
                            this.$message.success(res.msg);
                            this.ids = "";
                        } else {
                            this.$message.error(res.msg);
                        }
                    });
                });
            } else {
                this.$message({
                    showClose: true,
                    message: '请选择需要删除的招标人代表',
                    type: 'warning'
                });
            }
        }
    }
};
</script>
  